﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data.SqlClient;
using System.Data;
using System.Collections;
using System.Drawing;
using System.Drawing.Drawing2D;
using DataAccess;

namespace BusinessLogic
{
    public class GiaTriCombox : MarshalByRefObject
    {
        private static SqlCommand cmd;
        private static ArrayList arr;
        private static SqlDataReader dr;
        private static SqlConnection cn;


        public static Entities.GiaTriCombox[] sp_Select_Combox(Entities.GiaTriCombox combox)
        {
            Entities.GiaTriCombox[] list = null;
            try
            {
                cn = DataAccess.Connection.OpenConnection();
                cmd = new SqlCommand(Common.Constants.LayCombox.sp_LayCombox, cn);
                cmd.Parameters.Add(Common.Constants.LayCombox.tableName, SqlDbType.NVarChar).Value = combox.TenBang;
                cmd.Parameters.Add(Common.Constants.LayCombox.columnID, SqlDbType.NVarChar).Value = combox.TenCotKhoaChinh;
                cmd.Parameters.Add(Common.Constants.LayCombox.columnName, SqlDbType.NVarChar).Value = combox.TenCotTenHienThi;
                dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                arr = new ArrayList();
                while (dr.Read())
                {
                    Entities.GiaTriCombox row = new Entities.GiaTriCombox();
                    row.TenCotKhoaChinh = dr[0].ToString();
                    row.TenCotTenHienThi = dr[1].ToString();
                    arr.Add(row);
                }
                int n = arr.Count;
                if (n == 0) { list = null; }
                list = new Entities.GiaTriCombox[n];
                for (int i = 0; i < n; i++)
                {
                    list[i] = (Entities.GiaTriCombox)arr[i];
                }
            }
            catch (Exception ex)
            { string s = ex.Message.ToString(); list = null; }
            finally
            {
                cmd.Connection.Dispose();
                cn.Close();
            }
            return list;
        }

        /// <summary>
        /// loivt
        /// </summary>
        /// <param name="combox"></param>
        /// <returns></returns>
        public static Entities.NhanVien[] sp_Select_ComboxThuKho(string madiadiem)
        {
            Entities.NhanVien[] list = null;
            try
            {
                cn = DataAccess.Connection.OpenConnection();
                cmd = new SqlCommand(Common.Constants.LayCombox.sp_LayComboxThuKho, cn);
                cmd.Parameters.Add(Common.Constants.LayCombox.MaDiaDiem, SqlDbType.VarChar,50).Value = madiadiem;
                dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                arr = new ArrayList();
                while (dr.Read())
                {
                    Entities.NhanVien row = new Entities.NhanVien();
                    row.MaNhanVien = dr[0].ToString();
                    row.TenNhanVien = dr[1].ToString();
                    arr.Add(row);
                }
                int n = arr.Count;
                if (n == 0) { list = null; }
                list = new Entities.NhanVien[n];
                for (int i = 0; i < n; i++)
                {
                    list[i] = (Entities.NhanVien)arr[i];
                }
            }
            catch (Exception ex)
            { string s = ex.Message.ToString(); list = null; }
            finally
            {
                cmd.Connection.Dispose();
                cn.Close();
            }
            return list;
        }


        public static Entities.GiaTriCombox[] sp_ComboxTienTe(Entities.GiaTriCombox combox)
        {
            Entities.GiaTriCombox[] list = null;
            try
            {
                cn = DataAccess.Connection.OpenConnection();
                cmd = new SqlCommand(Common.Constants.LayCombox.sp_ComboxTienTe, cn);
                cmd.Parameters.Add(Common.Constants.LayCombox.HanhDong, SqlDbType.VarChar).Value = combox.HanhDong;
                cmd.Parameters.Add(Common.Constants.LayCombox.MaTienTe, SqlDbType.VarChar).Value = combox.GiaTri;
                dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                arr = new ArrayList();
                while (dr.Read())
                {
                    Entities.GiaTriCombox row = new Entities.GiaTriCombox();
                    row.TenCotKhoaChinh = dr[0].ToString();
                    row.TenCotTenHienThi = dr[1].ToString();
                    row.GiaTri = dr[2].ToString();
                    arr.Add(row);
                }
                int n = arr.Count;
                if (n == 0) { list = null; }
                list = new Entities.GiaTriCombox[n];
                for (int i = 0; i < n; i++)
                {
                    list[i] = (Entities.GiaTriCombox)arr[i];
                }
            }
            catch (Exception ex)
            { string s = ex.Message.ToString(); list = null; }
            finally
            {
                cmd.Connection.Dispose();
                cn.Close();
            }
            return list;
        }
    }
}
